package com.yhm.testSpringMvc.ACM;

import java.util.ArrayList;
import java.util.List;

public class lanbdaTest {

    public static void main(String[] args) {

        List<People> peoples = createPeoples();
        double avage = peoples.stream().filter(people -> people.getName().indexOf("i")>0).mapToDouble(people-> people.getScore()).average().getAsDouble();

        System.out.println(avage);


    }
    static List<People> createPeoples(){
        People p = new People(90.0d, 34, "zhangsan");
        ArrayList<People> peoples = new ArrayList<People>();

        peoples.add(p);
        p =   new People(92.0d, 23, "lisi");
        peoples.add(p);
        p =   new People(56.0d, 54, "wangwu");
        peoples.add(p);
        p =   new People(12.0d, 43, "wangkai");
        peoples.add(p);
        p =   new People(12.0d, 67, "caodan");
        peoples.add(p);
        p =   new People(56.0d, 67, "daye");
        peoples.add(p);

        return peoples;
    }
    static class People{

        double score;
        int age;
        String name;

        public People(double score, int age, String name) {
            this.score = score;
            this.age = age;
            this.name = name;
        }

        @Override
        public String toString() {
            return "People{" +
                    "score=" + score +
                    ", age=" + age +
                    ", name='" + name + '\'' +
                    '}';
        }

        public double getScore() {
            return score;
        }

        public void setScore(double score) {
            this.score = score;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

}
